package com.zzyl.qianfan;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.zzyl.common.ai.BaiduAIProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class Demo {
    @Autowired
    private BaiduAIProperties baiduAIProperties;
    @Test
    public  void test() {
        // 使用安全认证AK/SK鉴权，替换下列示例中参数，安全认证Access Key替换your_iam_ak，Secret Key替换your_iam_sk，如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
        //Qianfan qianfan = new Qianfan("ALTAKUlcP8uGcZeofdlb9lxg16", "5dfcffd254144e8d837414a64f139b5b");
        Qianfan qianfan = new Qianfan(baiduAIProperties.getAccessKey(), baiduAIProperties.getSecretKey());

        // 指定模型
       ChatResponse resp = qianfan.chatCompletion()
                .model(baiduAIProperties.getQianfanModel())
                .system("你是诗人")
               .temperature(1.0)
               .topP(1.0)
               .maxOutputTokens(2048)
               .responseFormat("json_object")
                .addMessage("user", "创建一首诗")
                .execute();
        System.out.println(resp.getResult());
    }
}